const express = require('express');
const connection = require('../db');
const app = express();
const $sql = require('../config')

app.get('/seach', function(req, res) {

    connection.query($sql.sql.a, (err, users) =>{
        if(err){
            res.send('query error');
        }else{
            res.send(users);
        }
    });
});

app.post('/login_ps',(req,res) => {
	var sql = $sql.sql.b;
	var parem =req.body.account ;
	connection.query(sql,parem,(err, users) => {
		if(err){
		    res.send('query error');
		}else{
		    res.send(users);
		}
	})
});
app.post('/login_lo',(req,res) => {
	var sql = $sql.sql.d;
	var parem =req.body.account ;
	connection.query(sql,parem,(err, users) => {
		if(err){
		    res.send('query error');
		}else{
		    res.send(users);
		}
	})
});
app.put('/enroll_en',(req,res) => {
	var sql = $sql.sql.e;
	var parem =[req.body.name,req.body.account,req.body.password] ;
	connection.query(sql,parem,(err, users) => {
		if(err){
			console.log(err)
		    res.send(err);
		}else{
		    res.send(users);
		}
	})
});
app.get('/login_ac',(req,res) => {
	var sql = $sql.sql.c;
	var parem =req.body.account ;
	connection.query(sql,(err, users) => {
		if(err){
		    res.send('query error');
		}else{
		    res.send(users);
		}
	})
});
module.exports =app;